package com.common.jump;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.curry.android.util.IntentHelper;
import com.orangelife.mobile.app.application.ExitApplication;
import com.orangelife.mobile.constants.Constant;
import com.orangelife.mobile.login.activity.ResetPwdActivity;
import com.orangelife.mobile.pay.activity.PaidResultActivity;
import com.orangelife.mobile.pay.activity.UsersPaidActivity;
import com.orangelife.mobile.pay.biz.PaymentModule;

import java.util.ArrayList;
import java.util.Map;

/**
 * 下单成功(获取支付流水号),跳转到支付页
 * Created by wgf on 2016/7/22.
 */
public class PayJumper {

    public static void jumpToModPwd(Context context,boolean isPayPwd) {
        IntentHelper.getInstances().intentWithExtra(context,ResetPwdActivity.class,"isPayPwd",isPayPwd);
    }

    /** 跳转到支付界面 */
    public static void jumpToPay(Activity activity, Map<String, Object> mapOrderDetail, ArrayList<String> mLocalProductsList, String type, String tel) {
        Bundle bundle = new Bundle();
        bundle.putString("totalCost", String.valueOf(mapOrderDetail.get("totalCost")));
        bundle.putString("couponCost", String.valueOf(mapOrderDetail.get("couponCost")));
        bundle.putString("outtradeno", String.valueOf(mapOrderDetail.get("outtradeno")));
        bundle.putString("totalPrice", Constant.RMB_FLAG + String.valueOf(mapOrderDetail.get("totalCost")));
        bundle.putString("orderInfo", String.valueOf(mapOrderDetail.get("orderContent")));
        bundle.putString("points", String.valueOf(mapOrderDetail.get("points")));
        bundle.putString("productID", String.valueOf(mapOrderDetail.get("productID")));
        bundle.putString("phone", tel);
        bundle.putString("type", type);
        bundle.putString("status", "goods");
        bundle.putString("orderType", String.valueOf(mapOrderDetail.get("orderType")));
        bundle.putStringArrayList("productsID", mLocalProductsList);
        Intent intent = new Intent(activity, UsersPaidActivity.class);
        intent.putExtras(bundle);
        activity.startActivity(intent);
        IntentHelper.getInstances().jumpActivityAnimation(activity, false);
    }

    /** 订单商品详情跳转支付界面 */
    public static void jumpToPayFromGoodOrderDetail(Activity activity, String orderID, String paidMethod, String totalCost, String orderContent, String outtradeno, String points, String voucherMoney, ArrayList<String> listProducts, String orderType) {
        ExitApplication.getInstance().addPaidActivity(activity);
        Bundle bundle = new Bundle();
        bundle.putString("totalPrice", Constant.RMB_FLAG + String.valueOf(totalCost));
        bundle.putString("totalCost", totalCost);
        bundle.putString("outtradeno", outtradeno);
        bundle.putString("couponCost", voucherMoney);
        bundle.putString("orderID", orderID);
        bundle.putString("points", points);
        bundle.putString("orderInfo", orderContent);
        bundle.putBoolean("orderList", true);
        bundle.putString("status", "goods");
        bundle.putInt("type", 5);
        bundle.putString(PaymentModule.PAID_METHOD, paidMethod);
        bundle.putString("orderType", orderType);
        bundle.putStringArrayList("productsID", listProducts);
        Intent intent = new Intent(activity, UsersPaidActivity.class);
        intent.putExtras(bundle);
        activity.startActivityForResult(intent, 333);
        IntentHelper.getInstances().jumpActivityAnimation(activity, false);
    }

    /**
     * 商品租借、Web界面跳转支付界面
     *
     * @param orderID      订单ID
     * @param paidMethod   支付方法
     * @param totalCost    支付金额
     * @param orderContent 订单信息
     * @param outtradeno   支付流水号
     */
    public static void jumpToUsersPaid(Context context, String orderID, String paidMethod, String totalCost, String orderContent, String outtradeno, String points, String orderType) {
        if (context == null) {
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putString("orderID", orderID);
        bundle.putString(PaymentModule.PAID_METHOD, paidMethod);
        bundle.putString("orderType", orderType);
        bundle.putString("totalCost", totalCost);
        bundle.putString("totalPrice", Constant.RMB_FLAG + String.valueOf(totalCost));
        bundle.putString("orderInfo", orderContent);
        bundle.putString("outtradeno", outtradeno);
        if (points != null) {
            bundle.putString("points", points);
        }
        Intent intent = new Intent(context, UsersPaidActivity.class);
        intent.putExtras(bundle);
        context.startActivity(intent);
        IntentHelper.getInstances().jumpActivityAnimation(context, false);
    }

    /** 物业缴费的跳转支付界面 */
    public static void jumpToPayFromProperty(Context context, Map<String, Object> orderMap) {
        String outTradeNo = String.valueOf(orderMap.get("outtradeno"));//订单流水号
        String totalPrice = String.valueOf(orderMap.get("totalCost"));
        String totalCost = String.valueOf(orderMap.get("totalCost"));
        String orderInfo = String.valueOf(orderMap.get("orderContent"));
        String orderID = String.valueOf(orderMap.get("orerID"));
        String orderType = String.valueOf(orderMap.get("orerType"));
        Bundle bundle = new Bundle();
        bundle.putString("outtradeno", outTradeNo);
        bundle.putString("totalPrice", Constant.RMB_FLAG + String.valueOf(totalPrice));
        bundle.putString("totalCost", totalCost);
        bundle.putString("orderInfo", orderInfo);
        bundle.putString("orderID", orderID);
        bundle.putString("orderType", orderType);
        bundle.putString(PaymentModule.PAID_METHOD, PaymentModule.mode[4]);
        IntentHelper.getInstances().bundleWithExtra(context, UsersPaidActivity.class, bundle);
    }

    /** 物业缴费免支付直接跳转到结果页 */
    public static void jumpToPaidResultWithFree(Context context, Map<String, Object> orderMap) {
        String totalCost = String.valueOf(orderMap.get("totalCost"));
        String orderInfo = String.valueOf(orderMap.get("orderContent"));
        String orderID = String.valueOf(orderMap.get("orerID"));
        String orderType = String.valueOf(orderMap.get("orerType"));
        Intent intent = new Intent(context, PaidResultActivity.class);
        intent.putExtra("orderInfo", orderInfo);
        intent.putExtra("totalPrice", Constant.RMB_FLAG + totalCost);
        intent.putExtra("orderID", orderID);
        intent.putExtra("orderType", orderType);
        intent.putExtra(PaymentModule.PAID_METHOD, PaymentModule.mode[4]);
        context.startActivity(intent);
        IntentHelper.getInstances().jumpActivityAnimation(context, false);
    }

}
